package com.jayson.geng.pms.service;

import com.alibaba.fastjson.JSONObject;
import com.jayson.geng.pms.util.SendMailUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.mail.MessagingException;

@Service
public class MainService {

    @Autowired
    SendMailUtil sendMailUtil;

    public String submit(String data) {

        JSONObject jsonObject = JSONObject.parseObject(data);
        System.out.println(jsonObject.toJSONString());
        String content = "";
        content += "\n单位全称：\n" + jsonObject.getString("a1") + "\n";
        content += "\n单位性质：\n" + jsonObject.getString("a2") + "\n";
        content += "\n产业类别：\n" + jsonObject.getString("a3") + "\n";
        content += "\n联系人：\n" + jsonObject.getString("a4") + "\n";
        content += "\n办公电话：\n" + jsonObject.getString("a5") + "\n";
        content += "\n手机：\n" + jsonObject.getString("a6") + "\n";
        content += "\n单位简介：\n" + jsonObject.getString("a7") + "\n";
        content += "\n合作项目内容及要求达到技术指标：\n" + jsonObject.getString("a8") + "\n";
        content += "\n合作形式：\n" + jsonObject.getString("a9") + "\n";
        content += "\n其他要求：\n" + jsonObject.getString("a10") + "\n";
        try {
            sendMailUtil.send(content);
        } catch (MessagingException e) {
            return "{\"status\": \"failed\"}";
        }

        return "{\"status\": \"success\"}";
    }
}
